package web;

import domain.Data;
import service.User_Service;
import service.impl.User_ServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/userServlet")
public class UserServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置页面编码
        response.setContentType("text/html;charset=utf-8");
        request.setCharacterEncoding("utf-8");
        //实例化session对象
        HttpSession session = request.getSession();

        Object project_id = session.getAttribute("project_id");
        //实例化service对象
        User_Service user_service = new User_ServiceImpl();
        /*获取项目名*/
        Object project_name = user_service.findOneProject(project_id).getProject_name();
        request.setAttribute("project_name",project_name);

        /*查询该项目所有数据*/
        List<Data> data = user_service.ProjectData(project_id);
        request.setAttribute("project_data",data);
        System.out.println(data);
        request.getRequestDispatcher("/user.jsp").forward(request,response);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
